﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Table = FCNS.Data.Table;
using DoubleH.Utility;

namespace WuLiuS
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            InitEvent();
        }

        public void Init(string relatedOrderNO)
        {
            labelStoreOrderSNO.Content = relatedOrderNO;
            datePickerDateTime.SelectedDate = DateTime.Now;
            uCUniqueS1.Init(Table.UniqueS.EnumFlag.物流公司);
            buttonSave.IsEnabled = true;
        }

        private void InitEvent()
        {
            buttonSave.Click += (ss, ee) => Save();
        }

        private void Save()
        {
            if (!checkBoxMoney.IsChecked.Value && doubleUpDownMoney.Value == 0)
                if (MessageWindow.Show("", "运费金额为 0 ,自动更改状态为到付.", MessageBoxButton.YesNo) == MessageBoxResult.No)
                    return;

            Table.WuLiuS order = new Table.WuLiuS(labelStoreOrderSNO.Content.ToString());
            order.OrderDateTime = datePickerDateTime.SelectedDate.Value;
            order.Company = uCUniqueS1.SelectedObjectId;
            order.OrderNO = textBoxOrderNO.Text;
            order.Money = checkBoxMoney.IsChecked.Value ? 0 : doubleUpDownMoney.Value.Value;
            order.Note = textBoxNote.Text;

            Table.DataTableS.EnumDatabaseStatus result = order.Insert();
            MessageWindow.Show(result.ToString());
            if (result == Table.DataTableS.EnumDatabaseStatus.操作成功)
                this.Close();
        }
    }
}
